<?php
//This page just shows how you would use my library.  
//Look in exif.php for more information
//Enjoy.
define("EXIF_IFD0","IFD0");
define("EXIF_SUBIFD","SubIFD");
define("EXIF_MAKE","Make"); // 生产商
define("EXIF_MODEL","Model"); // 型号
define("EXIF_XRESOLUTION","xResolution"); // 水平分辨率 X dpi
define("EXIF_YRESOLUTION","yResolution"); // 水平分辨率 Y dpi
define("EXIF_RESOLUTIONUNIT","ResolutionUnit"); // 分辨率单位
define("EXIF_SOFTWARE","Software"); // 软件
define("EXIF_DATETIME","DateTime"); // 拍摄时间
define("EXIF_ARTIST","Artist"); // 作者
define("EXIF_YCBCRPOSITIONING","YCbCrPositioning"); // YCbCr的定位
define("EXIF_EXIFOFFSET","ExifOffset"); // Exif图像偏移
define("EXIF_EXPOSURETIME","ExposureTime"); // 曝光时间
define("EXIF_FNUMBER","FNumber"); // 光圈F值
define("EXIF_EXPOSUREPROGRAM","ExposureProgram"); // 曝光模式
define("EXIF_ISOSPEEDRATINGS","ISOSpeedRatings"); // ISO 速度
define("EXIF_EXIFVERSION","ExifVersion"); // Exif版本
define("EXIF_DATETIMEORIGINAL","DateTimeOriginal"); // 记录时间
define("EXIF_EXPOSUREBIASVALUE","ExposureBiasValue"); // 曝光补偿值
define("EXIF_MAXAPERTUREVALUE","MaxApertureValue"); // 最大光圈值
define("EXIF_METERINGMODE","MeteringMode"); // 测光模式
define("EXIF_FLASH","Flash"); // 闪光
define("EXIF_FOCALLENGTH","FocalLength"); // 焦距
define("EXIF_EXIFIMAGEWIDTH","ExifImageWidth"); // Exif图像宽度 像素
define("EXIF_EXIFIMAGEHEIGHT","ExifImageHeight"); // Exif图像高度 像素

require_once(dirname(__FILE__).'/exif.php');

class ExifInfo{
	private $result;
	private $verbose = 0;
	function __construct($path){
		$this->result = read_exif_data_raw($path,$this->verbose);
	}
	
	function getMake(){
		if(isset($this->result[EXIF_IFD0][EXIF_MAKE]))
			return $this->result[EXIF_IFD0][EXIF_MAKE];
		else
			return "NULL";
	}
	
	function getModel(){
		if(isset($this->result[EXIF_IFD0][EXIF_MODEL]))
			return $this->result[EXIF_IFD0][EXIF_MODEL];
		else
			return "NULL";
	}
	function getXResolution(){
		if(isset($this->result[EXIF_IFD0][EXIF_XRESOLUTION]))
			return $this->result[EXIF_IFD0][EXIF_XRESOLUTION];
		else
			return "NULL";
	}
	function getYResolution(){
		if(isset($this->result[EXIF_IFD0][EXIF_YRESOLUTION]))
			return $this->result[EXIF_IFD0][EXIF_YRESOLUTION];
		else
			return "NULL";
	}
	function getResolutionUnit(){
		if(isset($this->result[EXIF_IFD0][EXIF_RESOLUTIONUNIT]))
			return $this->result[EXIF_IFD0][EXIF_RESOLUTIONUNIT];
		else
			return "NULL";
	}
	function getSoftware(){
		if(isset($this->result[EXIF_IFD0][EXIF_SOFTWARE]))
			return $this->result[EXIF_IFD0][EXIF_SOFTWARE];
		else
			return "NULL";
	}
	function getDateTime(){
		if(isset($this->result[EXIF_IFD0][EXIF_DATETIME]))
			try{
				$str = $this->result[EXIF_IFD0][EXIF_DATETIME];
				return date("Y-m-d H:i:s",strtotime($str));
			}catch(Exception $ex){
				return "NULL";
			}
		else
			return "NULL";
	}
	function getArtist(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_ARTIST]))
			return $this->result[EXIF_SUBIFD][EXIF_ARTIST];
		else
			return "NULL";
	}
	function getYCbCrPositioning(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_YCBCRPOSITIONING]))
			return $this->result[EXIF_SUBIFD][EXIF_YCBCRPOSITIONING];
		else
			return "NULL";
	}
	function getExifOffset(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_EXIFOFFSET]))
			return $this->result[EXIF_SUBIFD][EXIF_EXIFOFFSET];
		else
			return "NULL";
	}
	function getExposureTime(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_EXPOSURETIME])){
			$str = $this->result[EXIF_SUBIFD][EXIF_EXPOSURETIME];
			$str = preg_split('/ /', $str);
			try{
				$str = $str[0];
				$str = preg_split('/\//', $str);
				$a = $str[0];
				$b = $str[1];
				return ((int)($b/$a));
			}catch(Exception $ex){
				return "NULL";
			}
		}else
			return "NULL";
	}
	function getFNumber(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_FNUMBER]))
			try{
				return ((float)($this->result[EXIF_SUBIFD][EXIF_FNUMBER]));
			}catch(Exception $ex){
				return "NULL";
			}
		else
			return "NULL";
	}
	function getExposureProgram(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_EXPOSUREPROGRAM]))
			return $this->result[EXIF_SUBIFD][EXIF_EXPOSUREPROGRAM];
		else
			return "NULL";
	}
	function getISOSpeedRatings(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_ISOSPEEDRATINGS]))
			return $this->result[EXIF_SUBIFD][EXIF_ISOSPEEDRATINGS];
		else
			return "NULL";
	}
	function getExifVersion(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_EXIFVERSION]))
			return $this->result[EXIF_SUBIFD][EXIF_EXIFVERSION];
		else
			return "NULL";
	}
	function getDateTimeOriginal(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_DATETIMEORIGINAL]))
			try{
				$str = $this->result[EXIF_SUBIFD][EXIF_DATETIMEORIGINAL];
				return date("Y-m-d H:i:s",strtotime($str));
			}catch(Exception $ex){
				return "NULL";
			}
		else
			return "NULL";
	}
	function getExposureBiasValue(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_EXPOSUREBIASVALUE])){
			$str = $this->result[EXIF_SUBIFD][EXIF_EXPOSUREBIASVALUE];
			$str = preg_split('/ /', $str);
			try{
				$str = number_format((float)$str[0], 2, '.', '');
				return $str;
			}catch(Exception $ex){
				return "NULL";
			}
		}else
			return "NULL";
	}
	function getMaxApertureValue(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_MAXAPERTUREVALUE]))
			try{
				return ((float)($this->result[EXIF_SUBIFD][EXIF_MAXAPERTUREVALUE]));
			}catch(Exception $ex){
				return "NULL";
			}
		else
			return "NULL";
	}
	function getMeteringMode(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_METERINGMODE]))
			return $this->result[EXIF_SUBIFD][EXIF_METERINGMODE];
		else
			return "NULL";
	}
	function getFlash(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_FLASH]))
			return $this->result[EXIF_SUBIFD][EXIF_FLASH];
		else
			return "NULL";
	}
	function getFocalLength(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_FOCALLENGTH]))
			try{
				return ((float)($this->result[EXIF_SUBIFD][EXIF_FOCALLENGTH]));
			}catch(Exception $ex){
				return "NULL";
			}
		else
			return "NULL";
	}
	function getExifImageWidth(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_EXIFIMAGEWIDTH]))
			try{
				return ((int)($this->result[EXIF_SUBIFD][EXIF_EXIFIMAGEWIDTH]));
			}catch(Exception $ex){
				return "NULL";
			}
		else
			return "NULL";
	}
	function getExifImageHeight(){
		if(isset($this->result[EXIF_SUBIFD][EXIF_EXIFIMAGEHEIGHT]))
			try{
				return ((int)($this->result[EXIF_SUBIFD][EXIF_EXIFIMAGEHEIGHT]));
			}catch(Exception $ex){
				return "NULL";
			}
		else
			return "NULL";
	}
}
?>